/************************************************************************************/
/*  Program name CAPFNDIMP_MENU_ENTRIES.sql                                         */
/*  Creater:  WONG Wing Kin (PCCW - UniHub)                                         */
/*************   History   *************************                                */
/* 30 NOV, 2005   WONG Wing Kin         First created                               */
/************************************************************************************/
SET SERVEROUTPUT ON SIZE 1000000;

--ALTER TRIGGER FND_MENU_ENTRIES_C_DELTRG DISABLE;
--ALTER TRIGGER FND_MENU_ENTRIES_C_INSTRG DISABLE;
--ALTER TRIGGER FND_MENU_ENTRIES_C_STMTRG DISABLE;
--ALTER TRIGGER FND_MENU_ENTRIES_C_UPDTRG DISABLE;

DECLARE
	lv_Prog_ID		VARCHAR2(100)	:=	'CAPFNDIMP_MENU_ENTRIES';

	lv_Scc_Count	NUMBER			:=	0;
	lv_Err_Count	NUMBER			:=	0;
	lv_Err_Msg		VARCHAR2(500)	:=	'No Error';

	CURSOR Cur_F IS
	SELECT
		*
	FROM		
		CRST_FND_MENU_ENTRIES;


	lv_Next_Seq_ID	NUMBER;

BEGIN

	FOR C1 IN Cur_F LOOP
		BEGIN
			INSERT INTO CRST_FND_MENU_ENTRIES_MAP VALUES
			(
			C1.MENU_ID,
			C1.ENTRY_SEQUENCE,
			CAPBRIMP_MAPPING.GetFNDMenuIDMapping(C1.MENU_ID),
			C1.ENTRY_SEQUENCE
			);

			INSERT INTO FND_MENU_ENTRIES
			VALUES
			(
			CAPBRIMP_MAPPING.GetFNDMenuIDMapping(C1.MENU_ID),		--MENU_ID,
			C1.ENTRY_SEQUENCE,
			C1.LAST_UPDATE_DATE,
			CAPBRIMP_COMMON.GetUser(C1.LAST_UPDATED_NAME),			--LAST_UPDATED_BY,
			C1.LAST_UPDATE_LOGIN,
			C1.CREATION_DATE,
			CAPBRIMP_COMMON.GetUser(C1.CREATED_NAME),				--CREATED_BY,
			CAPBRIMP_MAPPING.GetFNDMenuIDMapping(C1.SUB_MENU_ID),	--SUB_MENU_ID,
			C1.FUNCTION_ID,		--???
			C1.GRANT_FLAG
			);
		EXCEPTION
			WHEN OTHERS THEN
				DBMS_OUTPUT.Put_Line(SQLERRM);
				lv_Err_Count	:=	lv_Err_Count + 1;
		END;
		lv_Scc_Count	:=	lv_Scc_Count	+	1;
	END LOOP;

	IF	lv_Err_Count	>	0	THEN
		ROLLBACK;
	END IF;

	INSERT INTO CAPCNV_LOG(
		PROG_ID,
		PROCESS_DATE,
		RECORD_PROCESSED,
		RECORD_REJECTED,
		RECORD_EXTRACTED,
		ERR_MSG
	) VALUES (
		lv_Prog_ID,
		SYSDATE,
		lv_Scc_Count,
		lv_Err_Count,
		lv_Scc_Count-lv_Err_Count,
		lv_Err_Msg
	);

	COMMIT;
END;
/

--ALTER TRIGGER FND_MENU_ENTRIES_C_DELTRG ENABLE;
--ALTER TRIGGER FND_MENU_ENTRIES_C_INSTRG ENABLE;
--ALTER TRIGGER FND_MENU_ENTRIES_C_STMTRG ENABLE;
--ALTER TRIGGER FND_MENU_ENTRIES_C_UPDTRG ENABLE;
